package db;

import java.util.HashMap;
import java.util.List;

import dom.AdminAccount;
import dom.Book;
import dom.BookReservation;
import dom.StudentAccount;

public class LibraryDb {

	private HashMap<String,List<StudentAccount>> accounts = null;
	private List<Book> books = null;
	private List<BookReservation> reservedBooks = null;
	private List<AdminAccount> admins = null;
	
	private LibraryDbExporter dbExporter = new LibraryDbExporter();
	private LibraryDbLoader dbImporter = new LibraryDbLoader();
	
	private String libraryId;
	
	public LibraryDb(String libraryId) {
		this.libraryId = libraryId;
	}

	public HashMap<String, List<StudentAccount>> getAccounts() {
		accounts = dbImporter.getAccounts(libraryId);
		return accounts;
	}

	public void setAccounts(HashMap<String, List<StudentAccount>> accounts) {
		this.accounts = accounts;
	}

	public List<Book> getBooks() {
		books = dbImporter.getBooks(libraryId);
		return books;
	}
	
	public void saveBooks(){
		dbExporter.exportBooks(books,libraryId);
	}
	
	public void saveAccounts(){
		dbExporter.exportAccounts(accounts,libraryId);
	}
	

	public void setBooks(List<Book> books) {
		this.books = books;
	}

	public List<BookReservation> getReservedBooks() {
		return reservedBooks;
	}

	public void setReservedBooks(List<BookReservation> reservedBooks) {
		this.reservedBooks = reservedBooks;
	}

	public List<AdminAccount> getAdmins() {
		return admins;
	}

	public void setAdmins(List<AdminAccount> admins) {
		this.admins = admins;
	}
	
	public void exportAccounts(HashMap<String, List<StudentAccount>> accounts) {
		dbExporter.exportAccounts(accounts, libraryId);
	}
	
	public void exportBooks(List<Book> books) {
		dbExporter.exportBooks(books, libraryId);
	}
	
}
